Skip to content

Conversation

kcbanner
Copy link
Contributor

@kcbanner kcbanner commented Oct 7, 2025

Closes #25393
Closes #25431

  • Rework translate-c to integrate with the build system (by outputting error bundles on stdout) via --zig-integration. I followed a similar approach to what resinator does here.
  • Revive some of the removed cache integration logic in cmdTranslateC now that translate-c can return error bundles
  • Extract common logic into Compilation.translateC and rework both cmdTranslateC and cImport to use this
  • Fix inconsistent path separators (on Windows) when building the aro include path
  • Add ErrorBundle.addRootErrorMessageWithNotes (extracted from resinator)

Remaining TODOs:

@andrewrk
Copy link
Member

andrewrk commented Oct 7, 2025

Thanks for working on this!

I'm not sure what the process is for integrating changes to aro - since it also lives in a separate repo. Should I wait until the PR there is merged / should I include the other changes (error bundle logic) in a separate arocc PR?

As soon as it lands in main branch there, it can be backported here.

@kcbanner
Copy link
Contributor Author

kcbanner commented Oct 9, 2025

I decided to reduce the scope of this PR, and just include the translate-c / cImport changes. I'll make a separate PR to backport the translate-c and arocc changes I made recently (ziglang/translate-c#199, Vexu/arocc#895, Vexu/arocc#897), once they are both merged. Those don't need to block this PR.

I noticed that the --zig-integration change to resinator in this tree is not in the main resinator repo, so I'm following that same convention with the --zig-integration changes to translate-c here. I also moved the aro diagnostics -> ErrorBundle conversion logic into compiler/util.zig (following the same logic - that stuff is only needed for --zig-integration in both commands).

@kcbanner kcbanner marked this pull request as ready for review October 9, 2025 05:05
… error bundles on stdout) via --zig-integration

- Revive some of the removed cache integration logic in `cmdTranslateC` now that `translate-c` can return error bundles
- Fixup inconsistent path separators (on Windows) when building the aro include path
- Move some error bundle logic from resinator into aro.Diagnostics
- Add `ErrorBundle.addRootErrorMessageWithNotes` (extracted from resinator)
…llowed by .off or .warning

- translate-c: emit `file_system_inputs` even in the case of failure, if available
- translate-c: fixup emitting zero-length `file_system_inputs`
…lateC`

- Add std.zig.Server.allocErrorBundle, replace duplicates
@kcbanner kcbanner changed the title translate-c error handling, cache integration, and #include_next fixes Add error bundle support to translate-c, unify cmdTranslateC and cImport Oct 9, 2025
…g the current error

- Compilation: renameTmpIntoCache doesn't need to be pub after the `translateC` change
Copy link
Member

@andrewrk andrewrk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a ton for working on this! Only 1 blocker for you

const aro = @import("aro");
const ErrorBundle = std.zig.ErrorBundle;

pub fn aroDiagnosticsToErrorBundle(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I won't block the merge on this, but in the interest of avoiding "util" in namespaces I wonder if @Vexu would consider accepting this logic to live inside aro.Diagnostics. I see that aro already takes advantage of std.zig so it doesn't seem unreasonable to me.

Also won't block the merge on this, but the more flexible API is to take a *ErrorBundle.Wip and add the errors into it, rather than returning it as a return value. That's similar to how it's better to accept an array list and append to it rather than returning a fresh one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming that util file may have been the hardest part of this PR :D

I originally actually did place this in aro.Diagnostics.toErrorBundle, however there was a chicken / egg problem with the other ErrorBundle changes in this PR that toErrorBundle would have depended on in the aro repo - so I would have had to PR those changes separately here, PRed the toErrorBundle change to aro, then backported it here.

If Vexu is alright with it, then I can make that change to aro after this PR is merged, and make your suggested API change as well. Then I can backport that aro change once it lands.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds great!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OK with it as long as you add a test for it since it'll be otherwise unused there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, I will PR it there once this is merged.

.errors = error_bundle,
};
},
else => fatal("unexpected message type received from translate-c: {s}", .{@tagName(header.tag)}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI

Suggested change
else => fatal("unexpected message type received from translate-c: {s}", .{@tagName(header.tag)}),
else => fatal("unexpected message type received from translate-c: {t}", .{header.tag}),

@andrewrk
Copy link
Member

I'll let @squeek502 have another look but as far as I'm concerned it's ready to land.

@andrewrk andrewrk merged commit c17e186 into ziglang:master Oct 11, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants